<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/JSP/Common/head.jsp"%>
<div class="nowPosition">你所在的位置是添加供应商</div>
<div class="addOrd-div">
    <p style="padding-left: 8%;font-family: '楷体';color: red">${MESSAGE}</p>
    <form action="${pageContext.request.contextPath}/JSP/ord.go" method="post" id="addOrdForm">
        <input name="method" value="addOrd" type="hidden">
        <label>
            <span class='addOrd-span'>编号</span>
            <input id="ordCode" name="ordCode" type="text" class="addOrd-input-text inshadow txtclick" placeholder="编号" />
            <span style="color: red;font-family: '楷体';">*</span>
        </label><br />
        <label>
            <span class='addOrd-span'>名称</span>
            <input id="ordName" name="ordName" type="text" class="addOrd-input-text inshadow txtclick" placeholder="名称" />
            <span style="color: red;font-family: '楷体';">*</span>
        </label><br />
        <label>
            <span class='addOrd-span'>数量</span>
            <input id="count" name="count" type="text" class="addOrd-input-text inshadow txtclick" placeholder="数量" />
            <span style="color: red;font-family: '楷体';">*</span>
        </label><br />
        <label>
            <span class='addOrd-span'>数量单位</span>
            <input id="unit" name="unit" type="text" class="addOrd-input-text inshadow txtclick" placeholder="单位" />
            <span style="color: red;font-family: '楷体';">*</span>
        </label><br />
        <label>
            <span class='addOrd-span'>金额</span>
            <input id="totalPrice" name="totalPrice" type="text" class="addOrd-input-text inshadow txtclick" placeholder="金额" />
            <span  style="color: red;font-family: '楷体';">*</span>
        </label><br />
        <label>
            <span class='addOrd-span'>是否支付</span>
            <select id="isPay" name="isPay" class="addUser-genderSelect inshadow txtclick">
                <option value="">--请选择--</option>
                <option value="已支付">已支付</option>
                <option value="未支付">未支付</option>
            </select>
            <span style="color: red;font-family: '楷体';">*请选择</span>
        </label><br />
        <label>
            <span class='addOrd-span'>商品描述</span>
            <input id="describe" name="describe" type="text" class="addOrd-input-text inshadow txtclick" placeholder="商品描述" value="暂无" />
        </label><br />
        <label>
            <span class='addUser-span'>供应商</span>
            <select id="supId" name="supId" class="addUser-genderSelect inshadow txtclick"></select>
            <span style="color: red;font-family: '楷体';">*</span>
        </label><br />
        <label>
            <input id="saveOrd" type="button" class="btnclick addOrd-input-save inshadow-white" value="添加" />
        </label>
        <label>
            <input type="button" class="goback btnclick addOrd-input-goback inshadow-white" value="返回" />
        </label>
    </form>
</div>

<%@ include file="/JSP/Common/foot.jsp"%>
<%--<script type="text/javascript" src="${pageContext.request.contextPath}/JS/orderAdd.js" charset="GBK" ></script>--%>
<script type="text/javascript">
    $(function () {
        var ordCode = $("#ordCode");
        var ordName = $("#ordName");
        var count = $("#count");
        var unit = $("#unit");
        var totalPrice = $("#totalPrice");
        var isPay = $("#isPay");
        var describe = $("#describe");
        var supId = $("#supId");
        var saveOrd = $("#saveOrd");
        var addOrdForm = $("#addOrdForm");

        $.ajax({
            type : "GET",
            url : getPath() + "/JSP/ord.go",
            data : {method : "getSupNames"},
            dateType: "json",
            success:function (data) {
                if (data != null){
                    supId.html("");
                    var options = "<option value=\"0\">--请选择--</option>";
                    for (let i = 0; i < data.length; i++) {
                        options += "<option value=\"" + data[i].id + "\">" + data[i].supName + "</option>";
                    }
                    supId.html(options);
                    setStyles(supId.next(), {'color':'red'}, getImgCross() + "(请选择供应商)", false);
                }
            },
            error:function (data) {
                setStyles(supId.next(), {'color':'red'}, getImgCross() + "(请求错误)", false);
            }
        });

        ordCode.on({
            focus:function () {
                setStyles(ordCode.next(), {'color':'red'}, "(输入编号,不能为空)", false);
            },
            blur:function () {
                $.ajax({
                    type: "GET",
                    url: getPath() + "/JSP/ord.go",
                    data: {method: "ordCodeExist", ordCode:ordCode.val()},
                    success:function (data) {
                        if (data.ordCode == "exist"){
                            setStyles(ordCode.next(), {'color':'red'}, "(编号存在)", false);
                        }else {
                            setStyles(ordCode.next(), {'color':'#87CEED'}, "(OK)", true);
                        }
                    },
                    error:function (data) {
                        setStyles(ordCode.next(), {'color':'red'}, "(请求错误)", false);
                    }
                })
            }
        });

        ordName.on({
            focus:function () {
                setStyles(ordName.next(), {'color':'red'}, "(输入姓名,不能为空)", false);
            },
            blur:function () {
                var len = ordName.val().length;
                if (len > 0){
                    setStyles(ordName.next(), {'color':'#87CEEB'}, "(OK)", true);
                }else {
                    setStyles(ordName.next(), {'color':'red'}, "(不能为空)", false);
                }
            }
        });

        count.on({
            focus:function () {
                setStyles(count.next(), {'color':'red'}, "(输入商品数量,不能为空)", false);
            },
            blur:function () {
                var len = count.val().length;
                if (len > 0){
                    setStyles(count.next(), {'color':'#87CEEB'}, "(OK)", true);
                }else {
                    setStyles(count.next(), {'color':'red'}, "(不能为空)", false);
                }
            }
        });

        unit.on({
            focus:function () {
                setStyles(unit.next(), {'color':'red'}, "(输入商品数量单位,不能为空)", false);
            },
            blur:function () {
                var len = unit.val().length;
                if (len > 0){
                    setStyles(unit.next(), {'color':'#87CEEB'}, "(OK)", true);
                }else {
                    setStyles(unit.next(), {'color':'red'}, "(不能为空)", false);
                }
            }
        });

        totalPrice.on({
            focus:function () {
                setStyles(totalPrice.next(), {'color':'red'}, "(输入金额,不能为空)", false);
            },
            blur:function () {
                var len = totalPrice.val().length;
                if (len > 0){
                    setStyles(totalPrice.next(), {'color':'#87CEEB'}, "(OK)", true);
                }else {
                    setStyles(totalPrice.next(), {'color':'red'}, "(不能为空)", false);
                }
            }
        });

        totalPrice.on({
            focus:function () {
                setStyles(totalPrice.next(), {'color':'red'}, "(输入金额,不能为空)", false);
            },
            blur:function () {
                var len = totalPrice.val().length;
                if (len > 0){
                    setStyles(totalPrice.next(), {'color':'#87CEEB'}, "(OK)", true);
                }else {
                    setStyles(totalPrice.next(), {'color':'red'}, "(不能为空)", false);
                }
            }
        });

        isPay.on({
            blur:function () {
                var len = isPay.val().length;
                console.log(len);
                if (len > 2){
                    setStyles(isPay.next(), {'color':'#87CEEB'}, "(OK)", true);
                }else {
                    setStyles(isPay.next(), {'color':'red'}, "(请选择)", false);
                }
            }
        });

        supId.on({
            blur:function () {
                var v = supId.val();
                if (v.toString() != "0"){
                    setStyles(supId.next(), {'color':'#87CEEB'}, "(OK)", true);
                }else {
                    setStyles(supId.next(), {'color':'red'}, "(请选择)", false);
                }
            }
        });


        saveOrd.on({
            click:function (){
                console.log(ordCode.attr("validateStatus"));
                console.log(ordName.attr("validateStatus"));
                console.log(count.attr("validateStatus"));
                console.log(unit.attr("validateStatus"));
                console.log(totalPrice.attr("validateStatus"));
                console.log(isPay.attr("validateStatus"));
                console.log(supId.attr("validateStatus"));
                if(ordCode.attr("validateStatus") != "true"){
                    ordCode.blur();
                }else if(ordName.attr("validateStatus") != "true"){
                    ordName.blur();
                }else if(count.attr("validateStatus") != "true"){
                    count.blur();
                }else if(unit.attr("validateStatus") != "true"){
                    unit.blur();
                }else if(totalPrice.attr("validateStatus") != "true"){
                    totalPrice.blur();
                }else if(isPay.attr("validateStatus") != "true"){
                    isPay.blur();
                }else if(supId.attr("validateStatus") != "true"){
                    supId.blur();
                }else{
                    if(confirm("是否确认提交数据")){
                        addOrdForm.submit();
                    }
                }
            }
        });


    })
</script>